import axios from 'axios'
import md5 from 'md5'
/**
 * 环境配置
 * 开发 ------ develop
 * 测试 ------ test
 * 正式 ------ production
 * 连接app的服务 ----- app
*/
export const APP_ENVIRONMENT = 'develop'
const CONFIG = {
  develop: {
    base: '/wechat/',
    PLATFORM_PREFIX: 'cas-wechat',
    CHILD_URL: 'test-wechat',
    SECOND_DOMAIN: '/wechat',
    NEWS_IMG: 'http://test-wechat.jshtcm.com/apptestcfs/cfs-file/upload/image/',
    NISBASE: 'NIS/cas/mobile/evaluation/v56_update1/'
  },
  test: {
    base: '/wechat/',
    PLATFORM_PREFIX: 'cas-wechat',
    CHILD_URL: 'test-wechat',
    SECOND_DOMAIN: '/wechat',
    NEWS_IMG: 'http://test-wechat.jshtcm.com/apptestcfs/cfs-file/upload/image/',
    NISBASE: '/sf/NIS/cas/mobile/evaluation/v56_update1/'
  },
  production: {
    base: '/cas-wechat/',
    PLATFORM_PREFIX: 'cas-wechat',
    CHILD_URL: 'wechat',
    SECOND_DOMAIN: '/cas-wechat',
    NEWS_IMG: 'http://183.207.103.104/cfs-file/upload/',
    NISBASE: 'http://183.207.103.103:8093/NIS/cas/mobile/evaluation/v56_update1/'
  },
  app: {
    base: '/apptest/cas-app/',
    PLATFORM_PREFIX: 'cas',
    CHILD_URL: 'test-wechat',
    SECOND_DOMAIN: '/wechat',
    NEWS_IMG: 'http://192.168.1.121:8084/cfs-file/upload/'
  }
}
export var base = CONFIG[APP_ENVIRONMENT].base
export const PLATFORM_PREFIX = CONFIG[APP_ENVIRONMENT].PLATFORM_PREFIX
export const CHILD_URL = CONFIG[APP_ENVIRONMENT].CHILD_URL
export const SECOND_DOMAIN = CONFIG[APP_ENVIRONMENT].SECOND_DOMAIN
export const NEWS_IMG = CONFIG[APP_ENVIRONMENT].NEWS_IMG
export const NISBASE = CONFIG[APP_ENVIRONMENT].NISBASE

export const DOCTOR_AVATAR = 'http://183.207.103.104:8080/icon/'
export const TRANSFER_URL = `http://${CHILD_URL}.jshtcm.com${SECOND_DOMAIN}/#/transfer?deptId=`
export const PAY_URL = `${SECOND_DOMAIN}/?#/appointment/appoint-pay`
export const PAY_URL2 = `${SECOND_DOMAIN}/?#/pay/confirm`
export const TENANT_ID = 'hcn.jsszyy'
export const PRODUCT_ID = 'hcn.jsszyy.patient_wx'
export const PRODUCT_ID_DOCTOR = 'hcn.jsszyy.doctor_ios'
export const ROLE_ID = 'patient'
export const ROLE_ID_DOCTOR = 'hcn.jsszyy.doctor'
export const ORG_ID = '0ab18621-cc00-4c4a-9b35-4ff28a7d9bcc'
export const ORG_NAME = '江苏省中医院'
export const SUBMIT_SOURCE = 'HCN_patient_WX'
export const BAIDU_MAP_AK = '8gY8iuYTGIEzqZUN9N4OqIaGGlIhQgZv'
export const DOCTOR_LEVEL = {
  '231': '主任医师',
  '232': '副主任医师',
  '233': '主治医生',
  '234': '医师',
  '235': '医士',
  '236': '副主任中医师',
  '237': '主任中医师',
  '238': '国医大师，主任中医师',
  '239': '全国名中医，主任中医师'
}
export const PAYED_STATUS = ['未发药', '已发药', '已作废', '退药', '未执行', '已执行']
export const DOCTOR_TYPE = {
  '01': '全科医生',
  '02': '全科护士',
  '03': '公卫医生',
  '04': '公卫护士',
  '05': '计生医生',
  '06': '中医师',
  '09': '其他'
}
export const CONFIRM_PAY_TIPS = [
  {
    title: '初诊患者友情提示',
    content: '您好！感谢您选择江苏省中医院为您的健康护航。由于您是首次来我院就诊患者，为保障您的病历资料完整，请与就诊日当天，<span class="t6">携带有效身份证件，提前到我院人工挂号/收费窗口进行身份认证，确认后请直接前往诊区候诊。</span>'
  },
  {
    title: '复诊自费患者友情提示',
    content: '您好！感谢您选择江苏省中医院为您的健康护航，<span class="t6">您可于就诊当天按照选定的时间，直接前往医生诊区候诊。</span>'
  },
  {
    title: '复诊医保患者友情提示',
    content: '您好！感谢您选择江苏省中医院为您的健康护航，您可于就诊当天按照选定的时间，直接前往医生诊区候诊。就诊前(或者就诊后），<span class="t6">您可至人工挂号/收费窗口进行医保结算，并完成医保费用报销。</span>'
  },
  {
    title: '复诊公费医疗患者友情提示',
    content: '您好！感谢您选择江苏省中医院为您的健康护航，您是公费医疗患者，按照相关政策规定，<span class="t6">您需先到医院人工挂号/收费窗口进行身份验证（人证相符），验证通过后，可直接前往相应诊室候诊。就诊后，可至人工收费窗口完成缴费。</span>'
  },
  {
    title: '夏令时挂号提示',
    content: '您正在使用当天挂号功能，因医生的下班时间为：<br/><span class="t6">上午：12:00；<br/>下午：17:30；</span><br/>请按照约定时间及时前往医院就诊，避免因错过医生接诊时间而延误就诊。'
  },
  {
    title: '冬令时挂号提示',
    content: '您正在使用当天挂号功能，因医生的下班时间为：<br/><span class="t6">上午：12:00；<br/>下午：17:00；</span><br/>请按照约定时间及时前往医院就诊，避免因错过医生接诊时间而延误就诊。'
  },
  {
    title: '膏方预约友情提醒',
    content: '感谢您预约江苏省中医院膏方服务，预约成功后，请按如下流程：<br />一、带医保卡或身份证前往人工挂号处注册取号<br />二、至一楼大厅西侧“膏方服务处”进行登记电话、地址<br />三、开膏方<br/>四、交费->回家候膏'
  }
]
export const FAMUSE_DOCTORS = ['邹燕勤', '张继泽', '唐蜀华', '曹世宏', '徐福松', '单兆伟', '余承惠', '黄馥华', '殷明', '刘沈林', '黄煌', '马永桢', '谈勇', '赵可宁', '郁斌']
export const FAMUSE_DOCTOR_TIPS = '您好！按照医院相关要求，您可通过下载我院官方APP或拨打025-12580电话进行该位专家的号源预约。'
export const PAY_STATUS = ['全部', '待支付', '已支付', '超时未支付', '已退号退费']
export const DAOZHEN_URL = 'http://h5.witspring.com/jsszyy/view/home?channel_id=JSSZYY&outUrl=' + encodeURIComponent(TRANSFER_URL)
export function getSignature (params) {
  if (!localStorage.accessToken) {
    return ''
  }
  let params1 = localStorage.accessToken.slice(4, 8)
  let params2 = JSON.stringify(params)
  let arr = [params1, params2]
  arr.sort()
  const sign = md5(arr[0] + arr[1])
  return sign
}
// 通用ajax请求方法
export const commonAjax = (url, params = {}, needAuth = false) => {
  var instance = axios.create({
    headers: {
      'X-Access-Token': localStorage.getItem('accessToken'),
      'Content-Type': 'application/x-www-form-urlencoded',
      'X-Signature': getSignature(params)
    }
  })
  if (needAuth) {
    return instance.post(`${base}auth/${url}`, transformRequest(params))
  } else {
    return instance.post(`${base}${url}`, transformRequest(params))
  }
}
export function transformRequest (params) {
  let s = ''
  for (let i in params) {
    s += encodeURIComponent(i) + '=' + encodeURIComponent(params[i]) + '&'
  }
  return s
}
// 通用NIS请求方法
export const commonNISAjaxPost = (url, params) => {
  var instance = axios.create({
    headers: {
      'token': localStorage.getItem('accessToken'),
      'Content-Type': 'application/json'
    }
  })
  return instance.post(`${NISBASE}${url}`, params)
}
export const commonNISAjaxGet = (url) => {
  let instance = axios.create({
    headers: {
      'token': localStorage.getItem('accessToken'),
      'Content-Type': 'application/json'
    }
  })
  return instance.get(`${NISBASE}${url}`)
}
// 登录
export const requestLogin = params => axios.post(`${base}/logon/login`, params)
// 修改密码
export const requestModifyPassword = params => axios.post(`${base}/logon/changepwd`, params, {
  headers: {'X-Access-Token': localStorage.getItem('accessToken')}
})
// 保存医生信息
export const saveDoctorInfo = params => axios.post(`${base}/file/saveDoctInfo`, params, {
  headers: {
    'X-Access-Token': localStorage.getItem('accessToken'),
    'Content-Type': 'multipart/form-data'
  }
})
// 第三方接口： 查询个人信息
export const queryPersonInfo = (mobile, idCard) => axios.post(`${base}/third/logon/queryPersonInfo?mobile=${mobile}&idCard=${idCard}`)
export const thirdLogin = params => axios.post(`${base}/third/logon/login`, params)
export const getHistoryRegprepare = params => axios.post(`${base}/third/logon/getHistoryRegprepare`, params)
